;;;Locates BMPs associated with a menu and copies them, the .MNL (if exists), and the selected .MNS file
;;;to the BAKUP subfolder to the menu folder.
;;;Lists BMP's that are not found in the AutoCAD Support File Search Path.
;;;Look in the folder that the menu was loaded into AutoCAD from for these BMPs.
;;;Add their path to the AutoCAD Support File Search Path and rerun MENUBACKUP to copy them to the BAKUP folder.
;;;
;;;	Requires: DOSLIB (free from McNEEL & Associates)
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;     http://paracadd.com
;;;	All rights reserved.
;;;
;;;	Copyright: 1-26-2006
;;;	   Edited: 1-26-2006
;;;
(DEFUN C:MENUBACKUP ()
  (SETQ menufile_sel
	 (dos_getfiled
	   "Select Menu Source File for Backup"
	   "C:/Program Files/Autodesk/Menus/2010/"
	   "Custom User Interface (*.cui)|*.cui|Legacy Menu (*.mns)|*.mns||"
	 ) ;_ end of dos_getfilem
  ) ;_ end of SETQ
  (SETQ split_menu_path (DOS_SPLITPATH menufile_sel))
  (SETQ menuopenr (OPEN menufile_sel "r"))
  (SETQ bmp_list NIL
	no_bmp_list NIL)
  (while (setq menureadline (READ-LINE menuopenr))
    (if (wcmatch (strcase menureadline) "*.BMP*")
      (progn
	(setq bmpcnt 1)
        (while (wcmatch (substr (strcase menureadline) bmpcnt) "*.BMP*")
          (setq bmpcnt (1+ bmpcnt))
	)
	(setq bmpend 3)
	(while (not (wcmatch (substr (strcase menureadline) bmpcnt bmpend) " *.BMP"))
	  (setq bmpcnt (1- bmpcnt)
		bmpend (1+ bmpend)
	  )
	)
	(COND
          ((SETQ this_bmp (findfile (strcat (CAR split_menu_path) (CADR split_menu_path) (substr menureadline (+ bmpcnt 7) (- bmpend 7)))))
	    (setq bmp_list (append bmp_list (list this_bmp))))
          
	  (setq no_bmp_list (append no_bmp_list (list (substr menureadline (+ bmpcnt 7) (- bmpend 7)))))
	)
	(if (wcmatch (strcase (substr menureadline (+ bmpcnt bmpend 2))) "*.BMP*")
	  (progn
	    (princ "\n\t")
	    (princ (substr menureadline (+ bmpcnt bmpend 2)))
	    (princ)
	  )
	)
      )
    )
  )
  (setq menuloc (dos_splitpath menufile_sel))
  (setq backuploc (strcat (car menuloc)(cadr menuloc) "bakup"));strange but true - cannot dos_mkdir a folder named "backup"
  (dos_mkdir backuploc)
  (dos_copy menufile_sel backuploc)
  (dos_copy (strcat (substr menufile_sel 1 (- (strlen menufile_sel) 3)) "mnl") backuploc)
  (foreach n bmp_list
    (dos_copy n backuploc)
  )
  (COND
    (no_bmp_list
      (princ (strcat "\n\tTHESE IMAGES REQUIRED BY " menufile_sel " NOT FOUND IN " (strcat (CAR split_menu_path) (CADR split_menu_path)) "\n\n"))
      (foreach n no_bmp_list (princ "\n\t\t")(princ n)(princ))
    )
    (bmp_list (princ (strcat "\n\tALL IMAGES REQUIRED BY " menufile_sel " WERE FOUND IN " (strcat (CAR split_menu_path) (CADR split_menu_path)) "\n\n"))(PRINC))
  )
  (close menuopenr)
  (princ)
)